﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BaoJian;

namespace BaoJian.member.myinfo
{
    public partial class EditMyInfo : System.Web.UI.Page
    {
        private string UserID;
        private LYQ.BLL.Users bll = new LYQ.BLL.Users();
        private LYQ.Model.Users model;
        protected void Page_Load(object sender, EventArgs e)
        {
            UserID = HttpContext.Current.User.Identity.Name;      
            if (!Page.IsPostBack)
            {
                Tools.Common.IsAuthenticated();
                BindData();
            }
        }

        void BindData()
        {
              
            model = bll.GetModel(UserID);
            lblUserID.Text = UserID; 
            txtUserName.Text = model.UserName;
            txtAddress.Text = model.Address;
            if (model.Sex == "男")
            {
                sex.Checked = true;
            }
            else if (model.Sex == "女")
            {
                sex1.Checked = true;
            }            
            if (!String.IsNullOrEmpty(model.Tel))
            {
                string[] code = model.Tel.Split('-');
                Tel_area.Text = code[0];
                Tel_number.Text = code[1];
            }
            
            txtMobile.Text = model.Mobile;
            Year.Items.FindByValue(model.Birthday.Year.ToString()).Selected = true;
            Month.Items.FindByValue(model.Birthday.Month.ToString()).Selected = true;
            Day.Items.FindByValue(model.Birthday.Day.ToString()).Selected = true;


        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
             model = bll.GetModel(UserID);
             model.UserName = txtUserName.Text;
             model.Address = txtAddress.Text;
             model.Tel = Tel_area.Text.ToString()+"-"+Tel_number.Text.ToString();
             model.Mobile = txtMobile.Text;
             if (sex.Checked)
             {
                 model.Sex = "男";
             }
             else if (sex1.Checked)
             {
                 model.Sex = "女";
             }
             model.Province = Region.SelectedValue;
             string dt = Year.SelectedValue+"-"+Month.SelectedValue+"-"+Day.SelectedValue;
             model.Birthday = DateTime.Parse(dt);
             bll.Update(model);

             Edit.Visible = false;
             Update.Visible = true;
        }
    }
}
